#encoding=utf8
'''
Created on 2012-11-29

@author: Administrator
'''
from Processor import Processor;
from pub import Func, UserDict, RoomDict;
from pub.Config import Config;
from models import IdiomModel;
class GTClass(Processor):
    '''
    classdocs
    '''


    def __init__(self,):
        Processor.__init__(self,);
        self.__roomId = 0;
        self.__userId = 0;
    def dataValidtor(self, cmdContent):
        if not cmdContent:
            return False;
        paraLen = len(cmdContent);
        if paraLen == 2:
            self.__roomId = Func.strToInt(cmdContent[0], Config.I_SYS_ZERO);
            self.__userId = Func.strToInt(cmdContent[1], Config.I_SYS_ZERO);
            return True;        
        return False;     
    def outData(self,):
        room = RoomDict.getRoomFromDictById(self.__roomId);
        if not room:
            Func.sendError(self._sockObj, self._cmdId, Config.ERROR_MESSAGE_ROOM_DETAIL_NULL + ",roomId:" + Func.toStr(self.__roomId, 0));
            return False;
        
        user = RoomDict.findUserInRoom(self.__userId)[1];
        if not user:
            Func.sendError(self._sockObj, self._cmdId, Config.ERROR_MESSAGE_ROOM_USER_NO+ ",userId:" + Func.toStr(self.__userId, 0));
            return False;
        
        user.set_user_state(Config.I_USER_GAME_STATE_OVER);
        user.set_current_in_room(False);
        userNickName = user.get_user_nick_name();
        userPhoto = user.get_user_photo();
        nextUserId = self.__userId;
        nextUserNickName="";
        nextUserPhoto="";
        
        nextUser = RoomDict.getNextUserByPreUserId(room, self.__userId);
        
        if nextUser:
            nextUser.set_current_in_room(True);
            nextUserId = nextUser.get_user_id();
            nextUserNickName = nextUser.get_user_nick_name();
            nextUserPhoto = nextUser.get_user_photo();
        
        
        
        
        (okNum, overNum, seeNum) = RoomDict.getUserStateinRoom(room);
        sendStr = self.setPackage([self.__roomId, self.__userId,userNickName,userPhoto,nextUserId,nextUserNickName,nextUserPhoto, self.__nextKeyword, okNum, overNum, seeNum, Config.I_SYS_ONE]);
        Func.debugInfo("GT:" + sendStr);
        RoomDict.sendInfoToRoomAllUser(roomObj=room, cmd="", msg=sendStr, isPackage=False);
        return True;    